﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using WPFDemoMVVM.Helpers;
using WPFDemoMVVM.Model;
using WPFDemoMVVM.ViewModel;

namespace WPFDemoMVVM.View
{
    /// <summary>
    /// DataGridAndPageView.xaml 的交互逻辑
    /// </summary>
    public partial class DataGridAndPageView : Window
    {
        private List<EmployeeModel> employees;
        private ICollectionView collectionView;
        public DataGridAndPageView()
        {
            InitializeComponent();
            this.DataContext = App.Current.Services.GetService<DataGridAndPageViewModel>();

            WeakReferenceMessenger.Default.Register<CloseWindowMessage>(this, (r, m) =>
            {
                if (m.Value == "DataGridAndPageView")
                {
                    this.Close(); // 执行关闭操作
                }
            });
        }


        private void CollectionViewSource_Filter(object sender, FilterEventArgs e)
        {
            collectionView.Refresh();
        }

        private void queryKeyword_TextChanged(object sender, TextChangedEventArgs e)
        {
            CollectionViewSource.GetDefaultView(userInfoGrid.ItemsSource).Refresh();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            employees.Add(EmployeeModel.FakeOne());
            collectionView.Refresh();
        }


    }
}
